function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {

    $(".release_form").submit(function (e) {
        e.preventDefault();
        // $("#rich_content").attr("value", tinyMCE.activeEditor.getContent());
        let title = $(".input_txt2").val();
        let digest = $(".input_multxt").val();
        let category_id = $(".sel_opt").val();
        let content = tinyMCE.activeEditor.getContent();
        // alert(content);
        params = {
            title,
            digest,
            content,
            category_id
        };
        // TODO 发布完毕之后需要选中我的发布新闻
        $.ajax({
            url: "/user/news_release",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie('csrf_token')
            },
            success: function (resp) {
                if (resp.errno == "0") {
                    // 选中索引为6的左边单菜单
                    window.parent.fnChangeMenu(6);
                    // 滚动到顶部
                    window.parent.scrollTo(0, 0)
                } else {
                    alert(resp.errmsg)
                }
            }
        })
    })
});